const app = getApp()
Page({
	data: {
		baseUrl: app.globalData.baseUrl,
		text:'',
		zip:[],
		titlec:'',
		list:[]
	},
	onLoad(options) {
		var titlec
		if(options.title=='计划'){
			titlec='项目计划'
		}else{
			titlec='今日项目完成内容'
		}
		wx.setNavigationBarTitle({
			title: '工作'+options.title
		  })
		this.setData({
			titlec:titlec
		})
		this.ready()
	},
	ready(){
		app.indexApi.chaosong().then(a => {
			if (a.code == 0) {
				this.setData({
					list:a.data
				})
			}
		})
	},
	shanchu(e){
		let index = e.currentTarget.dataset.index
		var _this=this
		wx.showModal({
			title: '确认删除该附件', //提示的标题
			content: '', //提示的内容
			success: function(res) {
				if(res.confirm) {
					_this.data.zip.splice(index,1)
					_this.setData({
						zip:_this.data.zip
					})
				}
			}
		})
	},
	subMit(){
		var _this=this
		var stt
		var text
		if(this.data.titlec=="项目计划"){
			stt='myplan'
			text='planText'
		}else{
			stt='mythelog'
			text='logText'
		}
		app.indexApi[stt]({
			fileList:this.data.zip,
			[text]:this.data.text
		}).then(a => {
			if (a.code == 0) {
				wx.showToast({
					title: '提交成功', //提示的内容
					icon: 'none', //图标有success、error、loading、none四种
				 })
				 setTimeout(function(){
					wx.navigateTo({
						url: '/pages/project/list/view2?id='+a.data+'&title='+  _this.data.titlec
					})
				 },1000)
			}
		})
	},
	upLoad(){
		var _this=this
		wx.showActionSheet({
			itemList:['上传文件'], //文字数组
			success: (res) => {
			  switch(res.tapIndex) {
				case 0:
				wx.chooseMessageFile({
					count: 100, // 最多可以选择的文件个数，可以 0～100
					type: 'all', // 	所选的文件的类型
					success(res){
						var list=_this.data.zip
						wx.showLoading({
							title: '上传中',
						  })
						res.tempFiles.forEach((path) => {
							wx.uploadFile({
								url: _this.data.baseUrl + '/admin/picture/weChatUpload',
				            	filePath:path.path,
				            	name: 'file',
								header:{"Authorization": wx.getStorageSync('token'),"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"},
								formData: {
									orgname: path.name, 
								},
								success(res1){
									wx.hideLoading()
									const data = JSON.parse(res1.data)
									list.push(data.data)
									_this.setData({
										zip:list
									})
								}
							})
						})
						
						
					}
				})
			  }
			}
		  })
		
	}
})